#ifndef SOFT_I2C_H_
#define SOFT_I2C_H_

#include <REGF51RC.H>

// 定义I2C控制脚
sbit I2C_SCL = P1 ^ 0; // SCL时钟线
sbit I2C_SDA = P1 ^ 1; // SDA数据线

// I2C所有操作函数
void i2c_start(void);       // 发送I2C开始信号
void i2c_stop(void);        // 发送I2C停止信号
 unsigned char i2c_wait_ack(void); // I2C等待ACK信号
void i2c_ack(void);         // I2C发送ACK信号
void i2c_nack(void);        // I2C不发送ACK信号

void i2c_write_byte( unsigned char txd);    // I2C发送一个字节
 unsigned char i2c_read_byte( unsigned char ack);   // I2C读取一个字节
 unsigned char i2c_mem_write( unsigned char DevAddress,  unsigned char MemAddress,  unsigned char *pData,  unsigned short Len);              // I2C对指定器件、指定寄存器连续写入
 unsigned char i2c_mem_read( unsigned char DevAddress,  unsigned char MemAddress,  unsigned char *pBuffer,  unsigned short Len);             // I2C对指定器件、指定寄存器连续读取
 unsigned char i2c_write_bit( unsigned char DevAddress,  unsigned char addr,  unsigned char bitNum,  unsigned char Data);                    // 写入8位寄存器的一个位
 unsigned char i2c_write_bits( unsigned char DevAddress,  unsigned char addr,  unsigned char bitStart,  unsigned char length,  unsigned char Data); // 写入8位寄存器的多个位
 unsigned char i2c_read_bit( unsigned char DevAddress,  unsigned char addr,  unsigned char bitNum,  unsigned char *Data);                    // 读取一个位从8位器件的寄存器
 unsigned char i2c_read_bits( unsigned char DevAddress,  unsigned char addr,  unsigned char bitStart,  unsigned char length,  unsigned char *Data); // 读取8位寄存器的多个位

#endif
